/**
 * Created by tancw on 2017/3/24.
 */
jQuery.extend({//所有的json格式调用request、非json格式调用postData
    request:function(url, parameters, feedback){
        $.ajax({
            type: 'POST',
            dataType: "json",
            url: url,
            data: parameters,
            success: feedback,
            error:function(xhr){
                switch(xhr.status){
                    case 403:layer.msg("对不起，您无此权限！", 2, 1);break;
                    case 404:layer.msg("对不起，无此页面！", 2, 1);break;
                    case 500:layer.msg("内部错误，请联系管理员！", 2, 1);break;
                    case 504:layer.msg("超时，请联系管理员！", 2, 1);break;
                }
            }
        });
    },
    postData:function(url, parameters, feedback){
        $.ajax({
            type: 'POST',
            url: url,
            data: parameters,
            success: feedback,
            error:function(xhr){
                switch(xhr.status){
                    case 403:layer.msg("对不起，您无此权限！", 2, 1);break;
                    case 404:layer.msg("对不起，无此页面！", 2, 1);break;
                    case 500:layer.msg("内部错误，请联系管理员！", 2, 1);break;
                    case 504:layer.msg("超时，请联系管理员！", 2, 1);break;
                }
            }
        });
    }
});


function getCommJsonParams(divId){
    var p = {};
    var $focusDiv;
    if(divId!=undefined && divId!=null){
        $focusDiv = $("#"+divId);
    }else{
        $focusDiv = $("#search");
    }

    if($focusDiv!=undefined){
        var $inp = $(':input',$focusDiv);
        $.each($inp, function (i,n) {
            if($(n).attr("type")!="button"){
                var spname =$(n).attr("name")==undefined?"sp["+$(n).attr("id")+"]":"sp["+$(n).attr("name")+"]";
                var sp = eval("({'"+spname+"':'"+$.trim($(n).val())+"'})");
                p = $.extend(p,sp);
            }

        });
        var $sel = $('select',$focusDiv);
        $.each($sel, function (i,n) {
            var spname =$(n).attr("name")==undefined?"sp["+$(n).attr("id")+"]":"sp["+$(n).attr("name")+"]";
            var sp = eval("({'"+spname+"':'"+$('option:selected',$(n)).attr("value")+"'})");
            p = $.extend(p,sp);
        });
    }else{
        var $inp = $(':input');
        $.each($inp, function (i,n) {
            if($(n).attr("type")!="button"){
                var spname =$(n).attr("name")==undefined?"sp["+$(n).attr("id")+"]":"sp["+$(n).attr("name")+"]";
                var sp = eval("({'"+spname+"':'"+$(n).val()+"'})");
                p = $.extend(p,sp);
            }
        });
        var $sel = $('select');
        $.each($sel, function (i,n) {
            var spname =$(n).attr("name")==undefined?"sp["+$(n).attr("id")+"]":"sp["+$(n).attr("name")+"]";
            var sp = eval("({'"+spname+"':'"+$('option:selected',$(n)).attr("value")+"'})");
            p = $.extend(p,sp);
        });
    }
    return p;
} ;